<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        项目信息-人员信息
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../../../../js/xm-select.js"></script>

</head>
<!--借还流水-->
<style>
    .layui-form-label {
        width: 150px !important;
    }
</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <div class="main_box">
        <div class="panel-heading">
            <ul class="nav nav-tabs" id="navTabs">
                <li class=""><a class="receivePane" data-tab=""  href="#" onclick="p_admin_add('项目详情','essential_information/essential_information.html?recordId='+recordId +'&businessTypeId=' + businessTypeId,'1200','600')">基本信息</a></li>
                <li class="active"><a class="payPane" data-tab="" href="#" onclick="p_admin_add('项目详情','personnel_information.html?recordId='+recordId +'&businessTypeId=' + businessTypeId,'1200','600')">人员信息</a></li>
                <li class=""><a class="payPane" data-tab="" href="#" onclick="p_admin_add('项目详情','tracking_phase/tracking_phase.html?recordId='+recordId +'&businessTypeId=' + businessTypeId,'1200','600')">跟踪阶段</a></li>
                <li class=""><a class="payPane" data-tab="" href="#" onclick="p_admin_add('项目详情','visit_records/visit_records.html?recordId='+recordId +'&businessTypeId=' + businessTypeId,'1200','600')">拜访记录</a></li>

                <li class=""><a class="payPane" data-tab="" href="#" onclick="p_admin_add('项目详情','project_log/project_log.html?recordId='+recordId +'&businessTypeId=' + businessTypeId,'1200','600')">项目日志</a></li>

            </ul>
        </div>
    </div>



    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-form-item">
                    <label class="layui-form-label">业务负责人</label>
                    <div class="layui-input-block" style="margin-left: 150px;">
                        <select name="projectId" id="businessId" lay-search="">
                            <option value="">--请选择业务负责人--</option>
                        </select>
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        提交
                    </button>
                </div>
                <!--</form>-->


                <div style="height:20px;"></div>
            </div>


        </div>

    </form>

    <h3>项目联系人：</h3>

    <button style="float: right;" class="layui-btn" onclick="admin_add('添加信息','personnel_information_add.html?projectId='+recordId,'','700')"><i class="layui-icon"></i>添加
    </button>
    <table class="layui-table" id="test" lay-filter="test">

    </table>

</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        element = layui.element;//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");
    var businessTypeId = getQueryVariable("businessTypeId");

    var nowUpId = null;

    layui.use(['laydate', 'form', 'layer','table'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var table = layui.table;
            morensele();


            var t1 = table.render({
                elem: '#test',
                url: $baseUrl + 'xa/projectLinkman/findProjectLinkman',
                where: {
                    userId: $userId,
                    projectId:recordId,
                    businessTypeId:0,
                },
                headers: {
                    token: $token
                }
                , toolbar: '#toolbarDemo',

                // toolbar: true,
                cols: [
                    [
                        {
                            field: 'id',
                            type:'numbers',
                            title: '序号',
                        },
                        {
                            field: 'linkmanName',
                            title: '姓名',
                            style: 'color: #145CCD;'
                        },
                        {
                            field: 'linkmanTel',
                            title: '手机号',
                            style: 'color: #145CCD;'
                        },
                        {
                            field: 'linkmanPosition',
                            title: ' 职务',
                        },
                        {
                            field: 'linkmanMemo',
                            title: '备注',
                        },
                        {
                            field: 'status',
                            title: '操作',
                            templet: '#barDemo',
                            fixed: 'right',
                            width: '20%'
                        }

                     ]
                ],
                request: {
                    pageName: 'pageNum', //页码的参数名称，默认：page
                    limitName: 'pageSize',
                },
                response: {
                    statusName: 'code' //规定数据状态的字段名称，默认：code
                    ,
                    statusCode: 0 //规定成功的状态码，默认：0
                    ,
                    msgName: 'msg' //规定状态信息的字段名称，默认：msg
                    ,
                    countName: 'total' //规定数据总数的字段名称，默认：count
                    ,
                    dataName: 'data', //规定数据列表的字段名称，默认：data
                },
                id: 'test',
                page: true,
                height: 'auto',
                even: true,
                done: function (res, curr, count) {


                }
            });

            //监听提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    console.log(form)
                    form.id = nowUpId;
                    form.userId = $userId;
                    form.projectId = recordId;
                    form.businessTypeId = businessTypeId;
                    form.linkmanId= $('#businessId[name=projectId]').val();
                    var selectValArr = (document.getElementById("businessId").options[document.getElementById("businessId").selectedIndex].text).split("-");
                    form.linkmanName= selectValArr[0];
                    form.linkmanTel= selectValArr[2];
                    form.linkmanPosition= selectValArr[1];
                    let request = {
                        url: 'xa/projectLinkman/addProjectLinkman',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {

                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });



            //监听工具条
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                let data = obj.data; //获得当前行数据
                let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                if (layEvent === 'del') { //删除
                    layer.confirm('是否确认删除 ？', {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        let request = {
                            url: "xa/projectLinkman/delProjectLinkman/" + data.id,
                            data: {
                                userId: $userId,
                            },
                            method: "DELETE",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("删除成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg("删除失败，请稍后再试！", {
                                    icon: 5
                                });
                            }
                        });
                        layer.close(index);
                    });
                }
            });


        });


    function morensele(){

        $.ajax({
            type:"get",
            url:baseHead + "xa/projectLinkman/findProjectLinkman",
            data:{
                userId :$userId,
                projectId:recordId,
                businessTypeId:businessTypeId,

            },
            headers: {
                token: $token
            },
            success:function(res){

               var linkmanId=res.data[0].linkmanId;
                nowUpId = res.data[0].id;
                getBusiness(linkmanId);
            }
        });
    }


    function getBusiness(linkmanId){
        // document.getElementById("projectId").innerHTML = "";
        $.ajax({
            type:"get",
            url:baseHead + "/user/findUserSelect",
            data:{
                userId :$userId,

            },
            headers: {
                token: $token
            },
            success:function(res){
                if(res.code == 0){
                    for(var i =0;i < res.data.length;i++){
                        if (linkmanId == res.data[i].id) {
                            $("#businessId").append("<option value=\""+res.data[i].id+"\" selected>"+res.data[i].nickname+ "-"+ res.data[i].department+"-"+res.data[i].phone+"</option>");
                        }else {
                            $("#businessId").append("<option value=\""+res.data[i].id+"\">"+res.data[i].nickname+ "-"+ res.data[i].department+"-"+res.data[i].phone+"</option>");
                        }

                    }
                    //重新渲染
                    layui.form.render("select");
                }else{
                    layer.msg(res.message);
                }
            }
        });
    };

    function p_admin_add(title,url,w,h){
        p_admin_show(title,url,w,h);
    }

</script>

</body>
<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-danger layui-btn-xs" style="background: red;" lay-event="del">删除</a>
</script>
</html>
